package com.example.hacteam;

import java.util.List;

import android.os.Bundle;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class ViewInicio extends Activity implements SensorEventListener {

	
	private Button btn_contact;
	private Sensor Acelerometro;
	TextView X,Y,Z;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_view_inicio);
		
		btn_contact = (Button) findViewById(R.id.button1);
		btn_contact.setOnClickListener(new View.OnClickListener() {
		    public void onClick(View view) {
		        Intent myIntent = new Intent( view.getContext(), ContactoBuscar.class);
		        startActivityForResult(myIntent, 0);
		    }
		});
		
		X=(TextView)findViewById(R.id.textViewX);
		Y=(TextView)findViewById(R.id.textViewY);
		Z=(TextView)findViewById(R.id.textViewZ);
		
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}

	
	protected void onResume()
	{
		super.onResume();
		SensorManager sm=(SensorManager)getSystemService(SENSOR_SERVICE);
		List<Sensor> sensors=sm.getSensorList(Sensor.TYPE_ACCELEROMETER);
		if (sensors.size()>0)
		{
		sm.registerListener(this, sensors.get(0),SensorManager.SENSOR_DELAY_NORMAL);
		
		}
	}
	/*
	protected void onPause()
	{
		
	}
	
	protected void onStop()
	{
		
	}
*/
	

	@Override
	public void onSensorChanged(SensorEvent event) 
	{
		
		X.setText("X: "+ event.values[SensorManager.DATA_X]);
		Y.setText("Y: "+event.values[SensorManager.DATA_Y]);
		Z.setText("Z: "+event.values[SensorManager.DATA_Z]);
		
		
			}
	
	
		
	
	
	
	
	
	
	
	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO Auto-generated method stub
		
	}
	
	
	
	

}
